/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package common.statistics;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author risto
 */
public class XYSeries implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -725321321948147021L;
	
	
	/**
	 * Series data
	 */
    private List<Double> xdata;
    private List<Double> ydata;

    /**
     * Add number
     * @param d
     */
    public void add(double x, double y) { xdata.add(x); ydata.add(y); }
    public void add(int x, int y) { add((double)x, (double)y); }

    public XYSeries() {
        xdata = new ArrayList<Double>();
        ydata = new ArrayList<Double>();
    }

    /**
     * Merge data from series s to this.
     * @param s
     */
    public void merge(XYSeries s) {
    	xdata.addAll(s.xdata);
    	ydata.addAll(s.ydata);
    }
    
    /**
     * Clear contents
     */
    public void clear()
    {
    	xdata.clear();
    	ydata.clear();
    }
    
    public int count()
    {
    	return xdata.size();
    }
    
    public double[] values()
    {
    	double[] arr = new double[xdata.size() + ydata.size()];
    	int i = 0;
    	for (double d : xdata) arr[i++] = d;
    	for (double d : ydata) arr[i++] = d;
    	return arr;
    }
}
